package org.karelun.gef.outline;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;

import org.eclipse.gef.editparts.AbstractTreeEditPart;
import org.karelun.gef.model.DiagramModel;
import org.karelun.gef.model.Node;

public class DiagramTreeEditPart extends AbstractTreeEditPart implements PropertyChangeListener {
	
	public DiagramTreeEditPart(Object model) {
		super(model);
	}

	public void activate() {
		super.activate();
		getDiagramModel().addPropertyChangeListener(this);
	}

	public void deactivate() {
		getDiagramModel().removePropertyChangeListener(this);
		super.deactivate();
	}

	protected List<Node> getModelChildren() {
		DiagramModel diagram = getDiagramModel();
		return diagram.getNodes();
	}

	public void propertyChange(PropertyChangeEvent evt) {
		if (evt.getPropertyName().equals(DiagramModel.PROP_NODE))
			refreshChildren();
	}
	
	private DiagramModel getDiagramModel(){
		return (DiagramModel)getModel();
	}
}
